package com.example.demo.packageModel;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
/**
*
*  @author author
*/
public class dept implements Serializable {

    private static final long serialVersionUID = 1595467579762L;


    /**
    * 
    * isNullAble:1
    */
    private Integer deptno;

    /**
    * 
    * isNullAble:1
    */
    private String dname;

    /**
    * 
    * isNullAble:1
    */
    private String loc;


    public void setDeptno(Integer deptno){this.deptno = deptno;}

    public Integer getDeptno(){return this.deptno;}

    public void setDname(String dname){this.dname = dname;}

    public String getDname(){return this.dname;}

    public void setLoc(String loc){this.loc = loc;}

    public String getLoc(){return this.loc;}
    @Override
    public String toString() {
        return "dept{" +
                "deptno='" + deptno + '\'' +
                "dname='" + dname + '\'' +
                "loc='" + loc + '\'' +
            '}';
    }

    public static Builder Build(){return new Builder();}

    public static ConditionBuilder ConditionBuild(){return new ConditionBuilder();}

    public static UpdateBuilder UpdateBuild(){return new UpdateBuilder();}

    public static QueryBuilder QueryBuild(){return new QueryBuilder();}

    public static class UpdateBuilder {

        private dept set;

        private ConditionBuilder where;

        public UpdateBuilder set(dept set){
            this.set = set;
            return this;
        }

        public dept getSet(){
            return this.set;
        }

        public UpdateBuilder where(ConditionBuilder where){
            this.where = where;
            return this;
        }

        public ConditionBuilder getWhere(){
            return this.where;
        }

        public UpdateBuilder build(){
            return this;
        }
    }

    public static class QueryBuilder extends dept{
        /**
        * 需要返回的列
        */
        private Map<String,Object> fetchFields;

        public Map<String,Object> getFetchFields(){return this.fetchFields;}

        private List<Integer> deptnoList;

        public List<Integer> getDeptnoList(){return this.deptnoList;}

        private Integer deptnoSt;

        private Integer deptnoEd;

        public Integer getDeptnoSt(){return this.deptnoSt;}

        public Integer getDeptnoEd(){return this.deptnoEd;}

        private List<String> dnameList;

        public List<String> getDnameList(){return this.dnameList;}


        private List<String> fuzzyDname;

        public List<String> getFuzzyDname(){return this.fuzzyDname;}

        private List<String> rightFuzzyDname;

        public List<String> getRightFuzzyDname(){return this.rightFuzzyDname;}
        private List<String> locList;

        public List<String> getLocList(){return this.locList;}


        private List<String> fuzzyLoc;

        public List<String> getFuzzyLoc(){return this.fuzzyLoc;}

        private List<String> rightFuzzyLoc;

        public List<String> getRightFuzzyLoc(){return this.rightFuzzyLoc;}
        private QueryBuilder (){
            this.fetchFields = new HashMap<>();
        }

        public QueryBuilder deptnoBetWeen(Integer deptnoSt,Integer deptnoEd){
            this.deptnoSt = deptnoSt;
            this.deptnoEd = deptnoEd;
            return this;
        }

        public QueryBuilder deptnoGreaterEqThan(Integer deptnoSt){
            this.deptnoSt = deptnoSt;
            return this;
        }
        public QueryBuilder deptnoLessEqThan(Integer deptnoEd){
            this.deptnoEd = deptnoEd;
            return this;
        }


        public QueryBuilder deptno(Integer deptno){
            setDeptno(deptno);
            return this;
        }

        public QueryBuilder deptnoList(Integer ... deptno){
            this.deptnoList = solveNullList(deptno);
            return this;
        }

        public QueryBuilder deptnoList(List<Integer> deptno){
            this.deptnoList = deptno;
            return this;
        }

        public QueryBuilder fetchDeptno(){
            setFetchFields("fetchFields","deptno");
            return this;
        }

        public QueryBuilder excludeDeptno(){
            setFetchFields("excludeFields","deptno");
            return this;
        }

        public QueryBuilder fuzzyDname (List<String> fuzzyDname){
            this.fuzzyDname = fuzzyDname;
            return this;
        }

        public QueryBuilder fuzzyDname (String ... fuzzyDname){
            this.fuzzyDname = solveNullList(fuzzyDname);
            return this;
        }

        public QueryBuilder rightFuzzyDname (List<String> rightFuzzyDname){
            this.rightFuzzyDname = rightFuzzyDname;
            return this;
        }

        public QueryBuilder rightFuzzyDname (String ... rightFuzzyDname){
            this.rightFuzzyDname = solveNullList(rightFuzzyDname);
            return this;
        }

        public QueryBuilder dname(String dname){
            setDname(dname);
            return this;
        }

        public QueryBuilder dnameList(String ... dname){
            this.dnameList = solveNullList(dname);
            return this;
        }

        public QueryBuilder dnameList(List<String> dname){
            this.dnameList = dname;
            return this;
        }

        public QueryBuilder fetchDname(){
            setFetchFields("fetchFields","dname");
            return this;
        }

        public QueryBuilder excludeDname(){
            setFetchFields("excludeFields","dname");
            return this;
        }

        public QueryBuilder fuzzyLoc (List<String> fuzzyLoc){
            this.fuzzyLoc = fuzzyLoc;
            return this;
        }

        public QueryBuilder fuzzyLoc (String ... fuzzyLoc){
            this.fuzzyLoc = solveNullList(fuzzyLoc);
            return this;
        }

        public QueryBuilder rightFuzzyLoc (List<String> rightFuzzyLoc){
            this.rightFuzzyLoc = rightFuzzyLoc;
            return this;
        }

        public QueryBuilder rightFuzzyLoc (String ... rightFuzzyLoc){
            this.rightFuzzyLoc = solveNullList(rightFuzzyLoc);
            return this;
        }

        public QueryBuilder loc(String loc){
            setLoc(loc);
            return this;
        }

        public QueryBuilder locList(String ... loc){
            this.locList = solveNullList(loc);
            return this;
        }

        public QueryBuilder locList(List<String> loc){
            this.locList = loc;
            return this;
        }

        public QueryBuilder fetchLoc(){
            setFetchFields("fetchFields","loc");
            return this;
        }

        public QueryBuilder excludeLoc(){
            setFetchFields("excludeFields","loc");
            return this;
        }
        private <T>List<T> solveNullList(T ... objs){
            if (objs != null){
            List<T> list = new ArrayList<>();
                for (T item : objs){
                    if (item != null){
                        list.add(item);
                    }
                }
                return list;
            }
            return null;
        }

        public QueryBuilder fetchAll(){
            this.fetchFields.put("AllFields",true);
            return this;
        }

        public QueryBuilder addField(String ... fields){
            List<String> list = new ArrayList<>();
            if (fields != null){
                for (String field : fields){
                    list.add(field);
                }
            }
            this.fetchFields.put("otherFields",list);
            return this;
        }
        @SuppressWarnings("unchecked")
        private void setFetchFields(String key,String val){
            Map<String,Boolean> fields= (Map<String, Boolean>) this.fetchFields.get(key);
            if (fields == null){
                fields = new HashMap<>();
            }
            fields.put(val,true);
            this.fetchFields.put(key,fields);
        }

        public dept build(){return this;}
    }


    public static class ConditionBuilder{
        private List<Integer> deptnoList;

        public List<Integer> getDeptnoList(){return this.deptnoList;}

        private Integer deptnoSt;

        private Integer deptnoEd;

        public Integer getDeptnoSt(){return this.deptnoSt;}

        public Integer getDeptnoEd(){return this.deptnoEd;}

        private List<String> dnameList;

        public List<String> getDnameList(){return this.dnameList;}


        private List<String> fuzzyDname;

        public List<String> getFuzzyDname(){return this.fuzzyDname;}

        private List<String> rightFuzzyDname;

        public List<String> getRightFuzzyDname(){return this.rightFuzzyDname;}
        private List<String> locList;

        public List<String> getLocList(){return this.locList;}


        private List<String> fuzzyLoc;

        public List<String> getFuzzyLoc(){return this.fuzzyLoc;}

        private List<String> rightFuzzyLoc;

        public List<String> getRightFuzzyLoc(){return this.rightFuzzyLoc;}

        public ConditionBuilder deptnoBetWeen(Integer deptnoSt,Integer deptnoEd){
            this.deptnoSt = deptnoSt;
            this.deptnoEd = deptnoEd;
            return this;
        }

        public ConditionBuilder deptnoGreaterEqThan(Integer deptnoSt){
            this.deptnoSt = deptnoSt;
            return this;
        }
        public ConditionBuilder deptnoLessEqThan(Integer deptnoEd){
            this.deptnoEd = deptnoEd;
            return this;
        }


        public ConditionBuilder deptnoList(Integer ... deptno){
            this.deptnoList = solveNullList(deptno);
            return this;
        }

        public ConditionBuilder deptnoList(List<Integer> deptno){
            this.deptnoList = deptno;
            return this;
        }

        public ConditionBuilder fuzzyDname (List<String> fuzzyDname){
            this.fuzzyDname = fuzzyDname;
            return this;
        }

        public ConditionBuilder fuzzyDname (String ... fuzzyDname){
            this.fuzzyDname = solveNullList(fuzzyDname);
            return this;
        }

        public ConditionBuilder rightFuzzyDname (List<String> rightFuzzyDname){
            this.rightFuzzyDname = rightFuzzyDname;
            return this;
        }

        public ConditionBuilder rightFuzzyDname (String ... rightFuzzyDname){
            this.rightFuzzyDname = solveNullList(rightFuzzyDname);
            return this;
        }

        public ConditionBuilder dnameList(String ... dname){
            this.dnameList = solveNullList(dname);
            return this;
        }

        public ConditionBuilder dnameList(List<String> dname){
            this.dnameList = dname;
            return this;
        }

        public ConditionBuilder fuzzyLoc (List<String> fuzzyLoc){
            this.fuzzyLoc = fuzzyLoc;
            return this;
        }

        public ConditionBuilder fuzzyLoc (String ... fuzzyLoc){
            this.fuzzyLoc = solveNullList(fuzzyLoc);
            return this;
        }

        public ConditionBuilder rightFuzzyLoc (List<String> rightFuzzyLoc){
            this.rightFuzzyLoc = rightFuzzyLoc;
            return this;
        }

        public ConditionBuilder rightFuzzyLoc (String ... rightFuzzyLoc){
            this.rightFuzzyLoc = solveNullList(rightFuzzyLoc);
            return this;
        }

        public ConditionBuilder locList(String ... loc){
            this.locList = solveNullList(loc);
            return this;
        }

        public ConditionBuilder locList(List<String> loc){
            this.locList = loc;
            return this;
        }

        private <T>List<T> solveNullList(T ... objs){
            if (objs != null){
            List<T> list = new ArrayList<>();
                for (T item : objs){
                    if (item != null){
                        list.add(item);
                    }
                }
                return list;
            }
            return null;
        }

        public ConditionBuilder build(){return this;}
    }

    public static class Builder {

        private dept obj;

        public Builder(){
            this.obj = new dept();
        }

        public Builder deptno(Integer deptno){
            this.obj.setDeptno(deptno);
            return this;
        }
        public Builder dname(String dname){
            this.obj.setDname(dname);
            return this;
        }
        public Builder loc(String loc){
            this.obj.setLoc(loc);
            return this;
        }
        public dept build(){return obj;}
    }

}
